<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='global-property-'>/**
</span> * @ignore
 * gesture single tap double tap
 * @author yiminghe@gmail.com
 */
KISSY.add('event/dom/touch/double-tap', function (S, eventHandleMap, DomEvent, SingleTouch) {
    var SINGLE_TAP = 'singleTap',
        DOUBLE_TAP = 'doubleTap',
    // same with native click delay
        MAX_DURATION = 300;

    function DoubleTap() {
    }

    S.extend(DoubleTap, SingleTouch, {
        onTouchStart: function (e) {
            var self = this;
            if (DoubleTap.superclass.onTouchStart.apply(self, arguments) === false) {
                return false;
            }
            self.startTime = e.timeStamp;
            if (self.singleTapTimer) {
                clearTimeout(self.singleTapTimer);
                self.singleTapTimer = 0;
            }
        },

        onTouchMove: function () {
            return false;
        },

        onTouchEnd: function (e) {
            var self = this,
                lastEndTime = self.lastEndTime,
                time = e.timeStamp,
                target = e.target,
                touch = e.changedTouches[0],
                duration = time - self.startTime;
            self.lastEndTime = time;
            // second touch end
            if (lastEndTime) {
                // time between current up and last up
                duration = time - lastEndTime;
                // a double tap
                if (duration &lt; MAX_DURATION) {
                    // a new double tap cycle
                    self.lastEndTime = 0;

                    DomEvent.fire(target, DOUBLE_TAP, {
                        touch: touch,
                        duration: duration / 1000
                    });
                    return;
                }
                // else treat as the first tap cycle
            }

            // time between down and up is long enough
            // then a singleTap
            duration = time - self.startTime;
            if (duration &gt; MAX_DURATION) {
                DomEvent.fire(target, SINGLE_TAP, {
                    touch: touch,
                    pageX: touch.pageX,
                    which: 1,
                    pageY: touch.pageY,
                    duration: duration / 1000
                })
            } else {
                // buffer singleTap
                // wait for a second tap
                self.singleTapTimer = setTimeout(function () {
                    DomEvent.fire(target, SINGLE_TAP, {
                        touch: touch,
                        pageX: touch.pageX,
                        which: 1,
                        pageY: touch.pageY,
                        duration: duration / 1000
                    });
                }, MAX_DURATION);
            }
        }
    });

    eventHandleMap[SINGLE_TAP] = eventHandleMap[DOUBLE_TAP] = {
        handle: new DoubleTap()
    };

    return DoubleTap;
}, {
    requires: ['./handle-map', 'event/dom/base', './single-touch']
});</pre>
</body>
</html>
